package com.yasaka.stock.model;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public final class LanguageList {
	
	private static final String BUNDLE_NAME = "language"; 
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
	
	private static final String BAIDU_NAME = "baidulanguage"; 
	private static final ResourceBundle BAIDU_BUNDLE = ResourceBundle.getBundle(BAIDU_NAME);
	
	private static final String GOOGLE_NAME = "googlelanguage"; 
	private static final ResourceBundle GOOGLE_BUNDLE = ResourceBundle.getBundle(GOOGLE_NAME);
	
	private static final String BIYING_NAME = "biyinglanguage"; 
	private static final ResourceBundle BIYING_BUNDLE = ResourceBundle.getBundle(BIYING_NAME);
	
	
	private static String getTransnLanguage(String key) {
		try {
			return RESOURCE_BUNDLE.getString(key);
		} catch (MissingResourceException e) {
			return '!' + key + '!';
		}
	}
	
	public static String getBaiduLanguageForTransnId(String aTransnId) {
		try {
			return BAIDU_BUNDLE.getString(aTransnId);
		} catch (MissingResourceException e) {
			return "auto";
		}
	}
	
	public static String getGoogleLanguageForTransnId(String aTransnId) {
		try {
			return GOOGLE_BUNDLE.getString(aTransnId);
		} catch (MissingResourceException e) {
			return "auto";
		}
	}
	
	public static String getBiyingForTransnId(String aTransnId) {
		try {
			return BIYING_BUNDLE.getString(aTransnId);
		} catch (MissingResourceException e) {
			return "auto";
		}
	}
	
	public static String getTransnLanguageId(TLanguageType aType,String aId){
		String mTransnId = getTransnLanguage(aType.getPrefix() + aId);		
		return mTransnId.replaceAll("Language.code.", "");		
	}
	
	public static String getLanguage(TLanguageType aType,String aId){		
		String mTransnId = getTransnLanguage(aType.getPrefix() + aId);		
		return getTransnLanguage(mTransnId);
	}

}
